package com.wenx.jettyCamel;

import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.model.RouteDefinition;

import java.net.URLEncoder;


public class JettyToMQProvider {
    public static void main(String[] args) throws Exception {
        CamelContext context = new DefaultCamelContext(); // 1. 创建 CamelContext.
        context.setTracing(true);
        context.start(); // 4. 启动CamelContext.
        context.addRouteDefinition(initRoute1());
        Thread.sleep(Integer.MAX_VALUE);  // 为了保持CamelContext处于工作状态，这里需要sleep主线程
        context.stop(); // 最后停止CamelContext
    }
    public static RouteDefinition initRoute1(){
        RouteDefinition routeDefinition = new RouteDefinition();
        routeDefinition
                .from("jetty:http://localhost:9080/camel/test1")
                .process(new Processor() {
                    @Override
                    public void process(Exchange exchange) throws Exception {
                        System.out.println("访问成功!");
                        //String param = exchange.getIn().getHeader(Exchange.HTTP_QUERY,String.class);
                        //String name = URLEncoder.encode("张三","utf-8");
                        //String name2 = URLEncoder.encode("abc张三","utf-8");
                        //String name3 = URLEncoder.encode("jgoewona","utf-8");
                        String encode = URLEncoder.encode("pk=张三", "utf-8");
                        exchange.getOut().setHeader(Exchange.HTTP_QUERY,encode);
                        //exchange.getOut().setHeader(Exchange.CHARSET_NAME,"utf-8");
                    }
                })
                .to("http://localhost:8084/depserver/api/v1/resourceCatalog/getResourceCatalogByPk?bridgeEndpoint=true");
        //.to("http://localhost:8084/depserver/api/v1/resourceCatalog/getResourceCatalogByPk?bridgeEndpoint=true&pk=5a1f8576-dc21-40d0-9405-a6fa5c6d85b6");
        return routeDefinition;
    }
}
